<?php

  session_start();

  if (isset($_SESSION['userid']) || isset($_SESSION['username']) || isset($_SESSION['user'])) {
    // Delete the session vars by clearing the $_SESSION array
    $_SESSION = array();

    // Delete the session cookie by setting its expiration to an hour ago (3600)
    if (isset($_COOKIE[session_name()])) {
      setcookie(session_name(), '', time() - 3600);
    }

    // Destroy the session
    session_destroy();

  }

  // Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
  setcookie('userid', '', time() - 3600);
  setcookie('username', '', time() - 3600);


  // Redirect to the home page
  $home_url = 'http://';
  $dir = dirname($_SERVER['PHP_SELF']);

  if( $dir == '\\'){

  	$home_url .= $_SERVER['HTTP_HOST'] . '/index.php';

  	//$home_url = $home_url . $_SERVER['HTTP_HOST'] . '/index.php';
  }else{
	$home_url .= $_SERVER['HTTP_HOST'] . $dir . '/index.php';
  }
  header('Location: ' . $home_url);
?>
